package com.example.demo.service;

import com.example.demo.dao.UserDAO;
import com.example.demo.entity.User;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class UserService{
    @Autowired
    private UserDAO userDAO;

    public void saveUser(User user){
        user.setId(RandomStringUtils.randomNumeric(6));
        userDAO.insert(user);
    }

    public User userExists(User user){
        return userDAO.findUser(user.getUsername());
    }

    public User select(User user){
        if(user.getUsername()==null|| user.getPassword()==null){
            return null;
        }
        return userDAO.selectOneUser(user);
    }
}

